package HuaweiOD;

import java.util.Scanner;

public class test3 {
    static int len = 0;
    static boolean[] vis;
    static String[] stBuild;
    static String[] strs;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        strs = in.nextLine().split(",");
        len = strs.length;
        vis = new boolean[len];
        stBuild = new String[len];
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i <len; i++) {
            if (vis[i]) {
                ans.append(stBuild[i]).append(',');
                continue;
            }
            String cur = check(strs[i]);
            if (cur.equals("-1")) {
                System.out.println("-1");
                return;
            }
            stBuild[i] = cur;
            ans.append(cur).append(',');
            vis[i] = true;
        }
        
        ans.deleteCharAt(ans.length() - 1);
        System.out.println(ans);
    }

    
    public static String check(String s){
        StringBuilder cur = new StringBuilder();
        int i = 0;
        boolean jdg = false;
        while (i < s.length()){
            char c = s.charAt(i);
            if (c >= '0' && c <= '9') {
                cur.append(c);
                i++;
            } else if (c == '<') {
                if (jdg || i + 2 > s.length()) return "-1";
                jdg = true;
                if (s.charAt(i + 2) != '>' || s.charAt(i + 1) < 'A' || s.charAt(i + 1) > 'A' + len) return "-1";
                int n = s.charAt(i + 1) - 'A';
                stBuild[n] = check(strs[n]);
                cur.append(stBuild[n]);
                vis[n] = true;
                i += 3;
            } else {
                return "-1";
            }
        }
        return cur.toString();
    }
}
